package com.hg.thread;

import javax.sound.midi.Soundbank;

/**
 * @Author: skh
 * @Date: 2019/12/20 11:21
 * @Description:
 */
public class TIcket2 {

    int num = 0;

    public synchronized void add() throws InterruptedException {
        //System.out.println(Thread.currentThread().getName() + "进入方法");
        while (num != 0) {
            //System.out.println(Thread.currentThread().getName() + "调用wait方法");
            //A C
            this.wait();

            //System.out.println(Thread.currentThread().getName() + "结束wait方法");

        }

        System.out.println(Thread.currentThread().getName()+":"+(++num));

        this.notifyAll();

        //System.out.println(Thread.currentThread().getName() + "结束方法");
    }

    public synchronized void decrease() throws InterruptedException {
        //System.out.println(Thread.currentThread().getName() + "进入方法");

        while (num == 0) {
            //System.out.println(Thread.currentThread().getName() + "调用wait方法");

            this.wait();

            //System.out.println(Thread.currentThread().getName() + "结束wait方法");

        }

        System.out.println(Thread.currentThread().getName()+":"+(--num));

        this.notifyAll();

        //System.out.println(Thread.currentThread().getName() + "结束方法");
    }

}
